//
//  CellForImage.m
//  MY Project For Sport
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForImage.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ModelForHotNews.h"
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"
#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CellForImage ()
@property (nonatomic, retain) UIImageView *imageviewFirst;
@property (nonatomic, retain) UIImageView *imageviewSecond;
@property (nonatomic, retain) UIImageView *imageviewThitd;
@property (nonatomic, retain) UILabel *labelForTitle;
@property (nonatomic, retain) UIView *view;
@end

@implementation CellForImage

- (void)dealloc {
    [_imageviewFirst release];
    [_imageviewSecond release];
    [_imageviewThitd release];
    [_labelForTitle release];
    [_view release];
    [super dealloc];
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithColors([UIColor linenColor], [UIColor grayColor]);
        
        [self createSubview];
        
    }
    
    return self;
    
    
}

- (void)createSubview {
    
    self.view = [[UIView alloc] init];
    [self.contentView addSubview:self.view];
    [_view release];

    
    self.imageviewFirst = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageviewFirst];
    [_imageviewFirst release];
    
    self.imageviewSecond = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageviewSecond];
    [_imageviewSecond release];
    
    self.imageviewThitd = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageviewThitd];
    [_imageviewThitd release];
    
    
    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
    
}

-(void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.view.frame = CGRectMake(2, 5, self.contentView.frame.size.width - 4, self.contentView.frame.size.height - 10);
    //self.view.backgroundColor = [UIColor whiteColor];
    self.view.dk_backgroundColorPicker = DKColorWithRGB (0xffffff, 0x343434);
    
    
    self.labelForTitle.frame = CGRectMake(2 * WEIGHTT, 5 * HEIGHTT, self.contentView.frame.size.width / 3 * 2, self.contentView.frame.size.height / 6);
    self.labelForTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    
    self.imageviewFirst.frame = CGRectMake(2 * WEIGHTT, 10 + HEIGHTT + self.contentView.frame.size.height / 5, (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, self.contentView.frame.size.height - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
    
    self.imageviewSecond.frame = CGRectMake(15 * WEIGHTT + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, 10 * HEIGHTT + self.contentView.frame.size.height / 5, (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, self.contentView.frame.size.height - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
    
    self.imageviewThitd.frame = CGRectMake(25 * WEIGHTT + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3 + (self.contentView.frame.size.width - 30 * WEIGHTT) / 3, 10 * HEIGHTT + self.contentView.frame.size.height / 5,(self.contentView.frame.size.width - 30 * WEIGHTT) / 3, self.contentView.frame.size.height - self.contentView.frame.size.height / 5 - 16 * HEIGHTT);
    
}

-(void)passModelForHotNews:(ModelForHotNews *)model {
    
    self.labelForTitle.text = model.title;
    
    /** 为每个图片model赋值 */
    if (model.img_data.count == 2) {
        
        [self.imageviewFirst sd_setImageWithURL:[NSURL URLWithString:[model.img_data[0] objectForKey:@"u"]]];
        [self.imageviewSecond sd_setImageWithURL:[NSURL URLWithString:[model.img_data[1] objectForKey:@"u"]]];
        [self.imageviewThitd sd_setImageWithURL:[NSURL URLWithString:[model.img_data[1] objectForKey:@"u"]]];
        
    } else if (model.img_data.count == 1) {
        
        [self.imageviewFirst sd_setImageWithURL:[NSURL URLWithString:[model.img_data[0] objectForKey:@"u"]]];
        [self.imageviewSecond sd_setImageWithURL:[NSURL URLWithString:[model.img_data[0] objectForKey:@"u"]]];
        [self.imageviewThitd sd_setImageWithURL:[NSURL URLWithString:[model.img_data[0] objectForKey:@"u"]]];
        
    } else {
        
        [self.imageviewFirst sd_setImageWithURL:[NSURL URLWithString:[model.img_data[0] objectForKey:@"u"]]];
        [self.imageviewSecond sd_setImageWithURL:[NSURL URLWithString:[model.img_data[1] objectForKey:@"u"]]];
        [self.imageviewThitd sd_setImageWithURL:[NSURL URLWithString:[model.img_data[2] objectForKey:@"u"]]];
        
    }
 }







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
